//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "RendistatoEquivalentSwapSpreadQuote.h"
using namespace Cephei::QL::Instruments::Bonds;
#include <gen/QL/Instruments/Bonds/RendistatoCalculator.h>
#include <gen/QL/Quote.h>
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::CRendistatoEquivalentSwapSpreadQuote (Cephei::QL::Instruments::Bonds::IRendistatoCalculator^ r) : CQuote(CRendistatoEquivalentSwapSpreadQuote::typeid)
{
    CRendistatoCalculator^ _Cr;
    try
    {
#ifdef HANDLE
        _phRendistatoEquivalentSwapSpreadQuote = NULL;
#endif
        _Cr = safe_cast<CRendistatoCalculator^> (r);
        _Cr->Lock();
        boost::shared_ptr<QuantLib::RendistatoCalculator>& _r = static_cast<boost::shared_ptr<QuantLib::RendistatoCalculator>&> (_Cr->GetShared ()); 
        _ppRendistatoEquivalentSwapSpreadQuote = new boost::shared_ptr<QuantLib::RendistatoEquivalentSwapSpreadQuote> (new QuantLib::RendistatoEquivalentSwapSpreadQuote ( _r ));
        SetQuote (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppRendistatoEquivalentSwapSpreadQuote));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cr != nullptr) _Cr->Unlock();
    }
}
Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::CRendistatoEquivalentSwapSpreadQuote (boost::shared_ptr<QuantLib::RendistatoEquivalentSwapSpreadQuote>& childNative, Object^ owner) : CQuote(CRendistatoEquivalentSwapSpreadQuote::typeid)
{
#ifdef HANDLE
	_phRendistatoEquivalentSwapSpreadQuote = NULL;
#endif
	_ppRendistatoEquivalentSwapSpreadQuote = &childNative;
    _ppQuote = new boost::shared_ptr<QuantLib::Quote> (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppRendistatoEquivalentSwapSpreadQuote));
}
Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::CRendistatoEquivalentSwapSpreadQuote (QuantLib::RendistatoEquivalentSwapSpreadQuote& childNative, Object^ owner) : CQuote(CRendistatoEquivalentSwapSpreadQuote::typeid)
{
#ifdef HANDLE
	_phRendistatoEquivalentSwapSpreadQuote = NULL;
#endif
	_ppRendistatoEquivalentSwapSpreadQuote = new boost::shared_ptr<QuantLib::RendistatoEquivalentSwapSpreadQuote> (&childNative);
    _ppQuote = new boost::shared_ptr<QuantLib::Quote> (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppRendistatoEquivalentSwapSpreadQuote));
    _RendistatoEquivalentSwapSpreadQuoteOwner = owner;
    _QuoteOwner = owner;
}

Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::CRendistatoEquivalentSwapSpreadQuote (CRendistatoEquivalentSwapSpreadQuote^ copy) : CQuote(CRendistatoEquivalentSwapSpreadQuote::typeid)
{
#ifdef HANDLE
	_phRendistatoEquivalentSwapSpreadQuote = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppRendistatoEquivalentSwapSpreadQuote = new boost::shared_ptr<QuantLib::RendistatoEquivalentSwapSpreadQuote> (copy->GetShared());
        _ppQuote = new boost::shared_ptr<QuantLib::Quote> (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppRendistatoEquivalentSwapSpreadQuote));
    }
}
Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::CRendistatoEquivalentSwapSpreadQuote (PLATFORM::Type^ t) : CQuote(CRendistatoEquivalentSwapSpreadQuote::typeid)
{
#ifdef HANDLE
	_phRendistatoEquivalentSwapSpreadQuote = NULL;
#endif
	if (!t->IsSubclassOf(CRendistatoEquivalentSwapSpreadQuote::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::CRendistatoEquivalentSwapSpreadQuote (QuantLib::Handle<QuantLib::RendistatoEquivalentSwapSpreadQuote>& childNative, Object^ owner)  : CQuote(CRendistatoEquivalentSwapSpreadQuote::typeid)
{
	_phRendistatoEquivalentSwapSpreadQuote = &childNative;
	_ppRendistatoEquivalentSwapSpreadQuote = &static_cast<boost::shared_ptr<QuantLib::RendistatoEquivalentSwapSpreadQuote>>(childNative.currentLink());
    _ppQuote = new boost::shared_ptr<QuantLib::Quote> (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppRendistatoEquivalentSwapSpreadQuote));
    _RendistatoEquivalentSwapSpreadQuoteOwner = owner;
}
Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::CRendistatoEquivalentSwapSpreadQuote (QuantLib::Handle<QuantLib::RendistatoEquivalentSwapSpreadQuote> childNative)  : CQuote(CRendistatoEquivalentSwapSpreadQuote::typeid)
{
	_phRendistatoEquivalentSwapSpreadQuote = &childNative;
	_ppRendistatoEquivalentSwapSpreadQuote = &static_cast<boost::shared_ptr<QuantLib::RendistatoEquivalentSwapSpreadQuote>>(childNative.currentLink());
    _ppQuote = new boost::shared_ptr<QuantLib::Quote> (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppRendistatoEquivalentSwapSpreadQuote));
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::CRendistatoEquivalentSwapSpreadQuote (QuantLib::RendistatoEquivalentSwapSpreadQuote childNative)  : CQuote(CRendistatoEquivalentSwapSpreadQuote::typeid)
{
#ifdef HANDLE
	_phRendistatoEquivalentSwapSpreadQuote = NULL;
#endif
	_ppRendistatoEquivalentSwapSpreadQuote = new boost::shared_ptr<QuantLib::RendistatoEquivalentSwapSpreadQuote> (new QuantLib::RendistatoEquivalentSwapSpreadQuote (childNative));
    _ppQuote = new boost::shared_ptr<QuantLib::Quote> (boost::dynamic_pointer_cast<QuantLib::Quote> (*_ppRendistatoEquivalentSwapSpreadQuote));
}
#endif

Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::~CRendistatoEquivalentSwapSpreadQuote ()
{
    if (_ppRendistatoEquivalentSwapSpreadQuote != NULL)
    {
	    delete _ppRendistatoEquivalentSwapSpreadQuote;
        _ppRendistatoEquivalentSwapSpreadQuote = NULL;
    }
}
Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::!CRendistatoEquivalentSwapSpreadQuote ()
{
    if (_ppRendistatoEquivalentSwapSpreadQuote != NULL)
    {
	    delete _ppRendistatoEquivalentSwapSpreadQuote;
    }
}
QuantLib::RendistatoEquivalentSwapSpreadQuote& Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::GetReference ()
{
    if (_ppRendistatoEquivalentSwapSpreadQuote == NULL) throw REFNEW NativeNullException ();
	return **_ppRendistatoEquivalentSwapSpreadQuote;
}
boost::shared_ptr<QuantLib::RendistatoEquivalentSwapSpreadQuote>& Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::GetShared ()
{
    if (_ppRendistatoEquivalentSwapSpreadQuote == NULL) throw REFNEW NativeNullException ();
	return *_ppRendistatoEquivalentSwapSpreadQuote;
}
QuantLib::RendistatoEquivalentSwapSpreadQuote* Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::GetPointer ()
{
    if (_ppRendistatoEquivalentSwapSpreadQuote == NULL) throw REFNEW NativeNullException ();
	return &**_ppRendistatoEquivalentSwapSpreadQuote;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::RendistatoEquivalentSwapSpreadQuote>& Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::GetHandle ()
{
	if (_phRendistatoEquivalentSwapSpreadQuote == NULL)
	{
		_phRendistatoEquivalentSwapSpreadQuote = new Handle<QuantLib::RendistatoEquivalentSwapSpreadQuote> (*_ppRendistatoEquivalentSwapSpreadQuote);
	}
	return *_phRendistatoEquivalentSwapSpreadQuote;
}
#endif
bool Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::HasNative () 
{
	return (_ppRendistatoEquivalentSwapSpreadQuote != NULL);
}

Boolean Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::IsValid::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppRendistatoEquivalentSwapSpreadQuote)->isValid ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote::Value::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppRendistatoEquivalentSwapSpreadQuote)->value ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Instruments::Bonds::IRendistatoEquivalentSwapSpreadQuote^ Cephei::QL::Instruments::Bonds::CRendistatoEquivalentSwapSpreadQuote_Factory::Create (Cephei::QL::Instruments::Bonds::IRendistatoCalculator^ r)
{
    return REFNEW CRendistatoEquivalentSwapSpreadQuote ( r);
}
